<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="PDF名称" prop="pdfBaseName">
        <el-input
          v-model="queryParams.pdfBaseName"
          placeholder="请输入PDF名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:base:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:base:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:base:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:base:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="baseList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="PDF名称" align="center" prop="pdfBaseName" />
      <el-table-column label="PDF标题" align="center" prop="pdfBaseTitle" />
<!--      <el-table-column label="PDF标题对齐方式" align="center" prop="pdfBaseTitleAlign">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.align_type" :value="scope.row.pdfBaseTitleAlign"/>
        </template>
      </el-table-column>
      <el-table-column label="PDF纸张宽" align="center" prop="pdfPaperWidth" />
      <el-table-column label="PDF纸张高" align="center" prop="pdfPaperHeight" />
      <el-table-column label="PDF左边距" align="center" prop="pdfPaperLeftMargin" />
      <el-table-column label="PDF右边距" align="center" prop="pdfPaperRightMargin" />
      <el-table-column label="PDF上边距" align="center" prop="pdfPaperTopMargin" />
      <el-table-column label="PDF下边距" align="center" prop="pdfPaperBottomMargin" />
      <el-table-column label="PDF描述表格数量" align="center" prop="pdfBaseDescNum" />
      <el-table-column label="字体路径" align="center" prop="pdfBaseFontPath" />
      <el-table-column label="PDF标题字体样式" align="center" prop="pdfBaseTitleFontStyle">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.font_style" :value="scope.row.pdfBaseTitleFontStyle"/>
        </template>
      </el-table-column>
      <el-table-column label="PDF标题字体大小" align="center" prop="pdfBaseTitleFontSize" />
      <el-table-column label="PDF标题字体颜色(RGB)" align="center" prop="pdfBaseTitleFontColor" />
      <el-table-column label="全局字体样式" align="center" prop="pdfBaseGlobalFontStyle">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.font_style" :value="scope.row.pdfBaseGlobalFontStyle"/>
        </template>
      </el-table-column>
      <el-table-column label="全局字体大小" align="center" prop="pdfBaseGlobalFontSize" />
      <el-table-column label="全局字体颜色(RGB)" align="center" prop="pdfBaseGlobalFontColor" />
      <el-table-column label="图片路径" align="center" prop="pdfBaseImagePath" />
      <el-table-column label="PDF文件保存地址" align="center" prop="pdfBaseSavePath" />-->
      <el-table-column label="备注信息" align="center" prop="remark" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:base:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:base:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改PDF基本配置对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="65%" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="140px">
        <el-form-item label="PDF名称" prop="pdfBaseName">
          <el-input v-model="form.pdfBaseName" placeholder="请输入PDF名称" />
        </el-form-item>
        <el-form-item label="PDF标题" prop="pdfBaseTitle">
          <el-input v-model="form.pdfBaseTitle" placeholder="请输入PDF标题" />
        </el-form-item>
        <el-form-item label="PDF标题对齐方式" prop="pdfBaseTitleAlign">
          <el-select v-model="form.pdfBaseTitleAlign" placeholder="请选择PDF标题对齐方式">
            <el-option
              v-for="dict in dict.type.align_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="PDF纸张宽" prop="pdfPaperWidth">
          <el-input v-model="form.pdfPaperWidth" placeholder="请输入PDF纸张宽" />
        </el-form-item>
        <el-form-item label="PDF纸张高" prop="pdfPaperHeight">
          <el-input v-model="form.pdfPaperHeight" placeholder="请输入PDF纸张高" />
        </el-form-item>
        <el-form-item label="PDF左边距" prop="pdfPaperLeftMargin">
          <el-input v-model="form.pdfPaperLeftMargin" placeholder="请输入PDF左边距" />
        </el-form-item>
        <el-form-item label="PDF右边距" prop="pdfPaperRightMargin">
          <el-input v-model="form.pdfPaperRightMargin" placeholder="请输入PDF右边距" />
        </el-form-item>
        <el-form-item label="PDF上边距" prop="pdfPaperTopMargin">
          <el-input v-model="form.pdfPaperTopMargin" placeholder="请输入PDF上边距" />
        </el-form-item>
        <el-form-item label="PDF下边距" prop="pdfPaperBottomMargin">
          <el-input v-model="form.pdfPaperBottomMargin" placeholder="请输入PDF下边距" />
        </el-form-item>
        <el-form-item label="PDF描述表格数量" prop="pdfBaseDescNum">
          <el-input v-model="form.pdfBaseDescNum" placeholder="请输入PDF描述表格数量" />
        </el-form-item>
        <el-form-item label="字体路径" prop="pdfBaseFontPath">
          <el-input v-model="form.pdfBaseFontPath" placeholder="请输入字体路径" />
        </el-form-item>
        <el-form-item label="PDF标题字体样式" prop="pdfBaseTitleFontStyle">
          <el-select v-model="form.pdfBaseTitleFontStyle" placeholder="请选择PDF标题字体样式">
            <el-option
              v-for="dict in dict.type.font_style"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="PDF标题字体大小" prop="pdfBaseTitleFontSize">
          <el-input v-model="form.pdfBaseTitleFontSize" placeholder="请输入PDF标题字体大小" />
        </el-form-item>
        <el-form-item label="PDF标题字体颜色(RGB)" prop="pdfBaseTitleFontColor">
          <el-input v-model="form.pdfBaseTitleFontColor" placeholder="请输入PDF标题字体颜色(RGB)" />
        </el-form-item>
        <el-form-item label="全局字体样式" prop="pdfBaseGlobalFontStyle">
          <el-select v-model="form.pdfBaseGlobalFontStyle" placeholder="请选择全局字体样式">
            <el-option
              v-for="dict in dict.type.font_style"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="全局字体大小" prop="pdfBaseGlobalFontSize">
          <el-input v-model="form.pdfBaseGlobalFontSize" placeholder="请输入全局字体大小" />
        </el-form-item>
        <el-form-item label="全局字体颜色(RGB)" prop="pdfBaseGlobalFontColor">
          <el-input v-model="form.pdfBaseGlobalFontColor" placeholder="请输入全局字体颜色(RGB)" />
        </el-form-item>
        <el-form-item label="图片路径" prop="pdfBaseImagePath">
          <el-input v-model="form.pdfBaseImagePath" placeholder="请输入图片路径" />
        </el-form-item>
        <el-form-item label="PDF文件保存地址" prop="pdfBaseSavePath">
          <el-input v-model="form.pdfBaseSavePath" placeholder="请输入PDF文件保存地址" />
        </el-form-item>
        <el-form-item label="备注信息" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listBase, getBase, delBase, addBase, updateBase } from "@/api/system/base";

export default {
  name: "Base",
  dicts: ['align_type', 'font_style'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // PDF基本配置表格数据
      baseList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        pdfBaseName: null,
        pdfBaseTitle: null,
        pdfBaseTitleAlign: null,
        pdfPaperWidth: null,
        pdfPaperHeight: null,
        pdfPaperLeftMargin: null,
        pdfPaperRightMargin: null,
        pdfPaperTopMargin: null,
        pdfPaperBottomMargin: null,
        pdfBaseDescNum: null,
        pdfBaseFontPath: null,
        pdfBaseTitleFontStyle: null,
        pdfBaseTitleFontSize: null,
        pdfBaseTitleFontColor: null,
        pdfBaseGlobalFontStyle: null,
        pdfBaseGlobalFontSize: null,
        pdfBaseGlobalFontColor: null,
        pdfBaseImagePath: null,
        pdfBaseSavePath: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        pdfBaseName: [{required: true, trigger: "blur", message: "PDF名称不能为空!"}],
        pdfBaseTitle: [{required: true, trigger: "blur", message: "PDF标题不能为空!"}],
        pdfBaseTitleAlign: [{required: true, trigger: "blur", message: "PDF标题对齐方式不能为空!"}],
        pdfPaperWidth: [{required: true, trigger: "blur", message: "PDF纸张宽不能为空!"}],
        pdfPaperHeight: [{required: true, trigger: "blur", message: "PDF纸张高不能为空!"}],
        pdfPaperLeftMargin: [{required: true, trigger: "blur", message: "PDF左边距不能为空!"}],
        pdfPaperRightMargin: [{required: true, trigger: "blur", message: "PDF右边距不能为空!"}],
        pdfPaperTopMargin: [{required: true, trigger: "blur", message: "PDF上边距不能为空!"}],
        pdfPaperBottomMargin: [{required: true, trigger: "blur", message: "PDF下边距不能为空!"}],
        pdfBaseDescNum: [{required: true, trigger: "blur", message: "PDF描述表格数量不能为空!"}],
        pdfBaseFontPath: [{required: true, trigger: "blur", message: "PDF字体路径不能为空!"}],
        pdfBaseTitleFontStyle: [{required: true, trigger: "blur", message: "PDF标题字体样式不能为空!"}],
        pdfBaseTitleFontSize: [{required: true, trigger: "blur", message: "PDF标题字体大小不能为空!"}],
        pdfBaseTitleFontColor: [{required: true, trigger: "blur", message: "PDF标题字体颜色(RGB)不能为空!"}],
        pdfBaseGlobalFontStyle: [{required: true, trigger: "blur", message: "PDF全局字体样式不能为空!"}],
        pdfBaseGlobalFontSize: [{required: true, trigger: "blur", message: "PDF全局字体大小不能为空!"}],
        // pdfBaseGlobalFontColor: [{required: true, trigger: "blur", message: "PDF全局字体颜色(RGB)不能为空!"}],
        pdfBaseImagePath: [{required: true, trigger: "blur", message: "图片路径不能为空!"}],
        pdfBaseSavePath: [{required: true, trigger: "blur", message: "PDF文件保存路径不能为空!"}]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询PDF基本配置列表 */
    getList() {
      this.loading = true;
      listBase(this.queryParams).then(response => {
        this.baseList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        pdfBaseName: null,
        pdfBaseTitle: null,
        pdfBaseTitleAlign: null,
        pdfPaperWidth: null,
        pdfPaperHeight: null,
        pdfPaperLeftMargin: null,
        pdfPaperRightMargin: null,
        pdfPaperTopMargin: null,
        pdfPaperBottomMargin: null,
        pdfBaseDescNum: null,
        pdfBaseFontPath: null,
        pdfBaseTitleFontStyle: null,
        pdfBaseTitleFontSize: null,
        pdfBaseTitleFontColor: null,
        pdfBaseGlobalFontStyle: null,
        pdfBaseGlobalFontSize: null,
        pdfBaseGlobalFontColor: null,
        pdfBaseImagePath: null,
        pdfBaseSavePath: null,
        createTime: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加PDF基本配置";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getBase(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改PDF基本配置";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateBase(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addBase(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除PDF基本配置编号为"' + ids + '"的数据项？').then(function() {
        return delBase(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/base/export', {
        ...this.queryParams
      }, `base_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
